<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/demo.css">
<script type="text/javascript" src="${pageContext.request.contextPath }/jq/jquery-3.2.1.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript">
$(function(){
	$("[type='submit']").click(function(){
		if($("[name='course.name']").val().length==0){
			$("#id1").html("请输入课程名称");
			$("[name='course.name']").focus();
			$("[name='course.name']").select();
			return false;
		}	
		if($("[name='course.type']").val().length==0){
			$("#id1").html("请输入课程类型");
			$("[name='course.type']").focus();
			$("[name='course.type']").select();
			return false;
		}
		if($("[name='course.hours']").val().length==0){
			$("#id1").html("请输入课程学时");
			$("[name='course.hours']").focus();
			$("[name='course.hours']").select();
			return false;
		}
		
		return true;	
	});	
		//删除课程
		$(".delete").click(function(){
			var flag=confirm("您真的要删除这个课程的信息吗");
			if(!flag){
				return;
			}
			$.post("${pageContext.request.contextPath }/course/delete",
					{"course.id":this.lang},function(data){
						location.href="${pageContext.request.contextPath }/course/main?page="+$("#page").val();
					}		
			);
		});
		//修改课程
		$(".modify").click(function(){
			$.post("${pageContext.request.contextPath }/course/get",{"course.id":this.lang},
					function(data){
						var info=data.split("!");
						$("#w [name='course.id']").val(info[0]);
						$("#w [name='course.name']").val(info[1]);
						$("#w [name='course.type']").val(info[2]);
						$("#w [name='course.hours']").val(info[3]);
					});
			$("#w").window("open");	
		});
			//保存
		$("#save").click(function(){
			$.post("${pageContext.request.contextPath }/course/modify",
			{"course.id":$("#w [name='course.id']").val(),
			 "course.name":$("#w [name='course.name']").val(),
			 "course.type":$("#w [name='course.type']").val(),
			 "course.hours":$("#w [name='course.hours']").val()
			},function(){
				$("#w").window("close");
				location.href="${pageContext.request.contextPath }/course/main?page="+$("#page").val();	
			});
		});
});
</script>
</head>
<body>
<input type="hidden" id="page" value="${page }">
<div id="w" class="easyui-window" title="Modal Window" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:500px;height:200px;padding:10px;">
	<input type="hidden" name="course.id">
	课程名称:<input type="text" name="course.name"> <br/>
	课程类型:<input type="text" name="course.type"><br/>
	课程学时:<input type="text" name="course.hours"><br/>
	<input type="submit" value="保存" id="save">
</div>

<form method="post" action="${pageContext.request.contextPath }/course/update">
	课程名称:<input type="text" name="course.name"> <br/>
	课程类型:<input type="text" name="course.type"><br/>
	课程学时:<input type="text" name="course.hours"><br/>
	<s:token></s:token>
	<input type="submit" value="提交">
</form>
<div id="id1"></div>
<s:if test="#COURSES!=null">
<table>
<tr><td>序号</td><td>课程名称</td><td>课程类型</td><td>课程学时</td><td>删除</td><td>修改</td></tr>
<s:iterator value="#COURSES" id="mycourse" status="st">
<tr><td>${st.index+1 }</td><td>${mycourse.name }</td><td>${mycourse.type }</td><td>${mycourse.hours }</td>
<td><input type="button" value="删除" class="delete" lang="${mycourse.id }"></td>
<td><input type="button" value="修改" class="modify" lang="${mycourse.id }"></td></tr>
</s:iterator>
</table>
${NAVBAR}
</s:if>
<br>
<a href="${pageContext.request.contextPath }/main.jsp">返回主页面</a>

</body>
</html>